<%@ page language="java" contentType="text/html; charset=windows-1255" pageEncoding="windows-1255"%>
<%@ taglib uri="http://java.sun.com/jsf/core" prefix="f" %>
<%@ taglib uri="http://java.sun.com/jsf/html" prefix="h" %>
<!-- RichFaces tag library declaration -->
<%@ taglib uri="http://richfaces.org/a4j" prefix="a4j"%>
<%@ taglib uri="http://richfaces.org/rich" prefix="rich"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <script type="text/javascript">
            function fillCst(id,acco,loc,state,zip,country, sgcomponent){
            	loc.value =sgcomponent.getSelectedItems().pluck('location');
            	id.value =sgcomponent.getSelectedItems().pluck('id');
            	acco.value =sgcomponent.getSelectedItems().pluck('accountancyId');
            	state.value =sgcomponent.getSelectedItems().pluck('state');
            	zip.value =sgcomponent.getSelectedItems().pluck('zipCode');
            	country.value =sgcomponent.getSelectedItems().pluck('country');
            }
            function fillPrd(id,des, sgcomponent){
            	id.value =sgcomponent.getSelectedItems().pluck('id');
            	des.value =sgcomponent.getSelectedItems().pluck('productName');

            }
            

            
        </script>

      <body>
            <f:view>
          <%@include file="../inc/menu.inc" %>
            <f:loadBundle basename="il" var="mes"/>
            <h:outputText style="font-size:30;color:#680000" value="#{mes.menu_pos_report}" />
             		    <br>
             		    <br>
            	<a4j:form>
            		<h:panelGrid columns="2">
	            		<rich:comboBox value="#{newPosManagedBean.selectedDraft}">           
	             		    	<f:selectItems   value="#{newPosManagedBean.draftsLabel}"  var = "draft" itemLabel="#{draft.value}" itemValue="#{draft.value}" />            
	             		</rich:comboBox>
	             		<a4j:commandButton value="#{mes.load_draft}" action="#{newPosManagedBean.loadDraft}" reRender="posPrdsTable, fields, mails" />
	             	</h:panelGrid>
            	   	<br>
                   	<br>
                   	<rich:panel id="mails">
						<h:outputText value="#{mes.email} "/>&nbsp;
                   		<h:inputText   value = "#{newPosManagedBean.email}" id = "email">
                   			<rich:ajaxValidator event="onblur"/>
                   		</h:inputText>&nbsp;
                   		<h:outputText  value="#{mes.emailcc}"/>&nbsp;
                   		<h:inputText   value = "#{newPosManagedBean.cc}" id="emailcc">
                   			<rich:ajaxValidator event="onblur"/>
                   		</h:inputText>&nbsp;
                   	</rich:panel> 
                    
                     <rich:message for="email" style="color:red;" /> &nbsp;&nbsp;
                     <rich:message for="emailcc" style="color:red;" />
                     <br>
                     <br> 
            		<rich:tabPanel id="fields" switchType="client">
            			<rich:tab label="#{mes.pos_tab_dpa}">
            			<h:panelGrid columns="2"> 
			        	<rich:extendedDataTable id="dpa" value="#{newPosManagedBean.dpaList}" var="dpa" width="380px" height="350px"  
			        	columnClasses="center" rows="10"  reRender="ds">
			            	<rich:column sortBy="#{dpa.dpaId}"> 
			                	<f:facet name="header">
			                    	<h:outputText value="#{mes.dpaid }"/>
			                	</f:facet>
				                <h:outputText value="#{dpa.dpaId}"/>
			            	</rich:column> 
			            	<rich:column sortBy="#{dpa.requestDate}" width="110px">
			                	<f:facet name="header">
				                    <h:outputText value="#{mes.date_request }"/>
				                </f:facet>
				                <h:outputText value="#{dpa.requestDate}"/> 
				            </rich:column>
				            <rich:column sortBy="#{dpa.customer.name}">
				                <f:facet name="header">
				                    <h:outputText value="#{mes.customer_name}"/>
				                </f:facet>
				              			<h:outputText id="id" value="#{dpa.customer.name}"/>
				            </rich:column>
				            <rich:column>
				                 <a4j:commandLink action= "#{newPosManagedBean.selectDpaFromTable}" value="#{mes.select }"  reRender="products">
				                		<a4j:actionparam name="id" value="#{dpa.dpaId}" assignTo="#{newPosManagedBean.selectedDpaIdFormTable}"/>
				                		
					            </a4j:commandLink>
				            </rich:column>
				            <f:facet name="footer">
				                <rich:datascroller id="ds"></rich:datascroller>
				            </f:facet>
				        </rich:extendedDataTable>
				        
				        <rich:extendedDataTable id="products" value="#{newPosManagedBean.productList}" var="prod" width="500px" height="350px"  
				        columnClasses="center"   rows="10"  reRender="ds2"   >
				        	<rich:column sortBy="#{prod.product.productName}">
				                <f:facet name="header">
				                    <h:outputText value="#{mes.product_name}"/>
				                </f:facet>
				                <h:outputText value="#{prod.product.productName}"/> 
				            </rich:column>
				            <rich:column sortBy="#{prod.sdc}">
				                <f:facet name="header">
				                    <h:outputText value="#{mes.sdc}"/>
				                </f:facet>
				                <h:outputText value="#{prod.sdc}"/> 
				            </rich:column>
				            <rich:column sortBy="#{prod.approvedPrice}">
				                <f:facet name="header">
				                    <h:outputText value="#{mes.approved_price}"/>
				                </f:facet>
				                <h:outputText value="#{prod.approvedPrice}"/> 
				            </rich:column>
				            <rich:column >
				                <f:facet name="header">
				                    <h:outputText value="#{mes.quantity_left}"/>
				                </f:facet>
				                <h:outputText value="#{prod.quantity-prod.quantityReported}"/> 
				            </rich:column>
				            
				            <rich:column>
				                 <a4j:commandLink value="#{mes.add }" action="#{newPosManagedBean.selectProdFromTable}"  reRender="fields">
				                		<a4j:actionparam name="sd" value="#{prod.product.id }" assignTo="#{newPosManagedBean.selectedProdFormTable}"/>
					            </a4j:commandLink>
				            </rich:column>
				            
				            
				            <f:facet name="footer">
				                <rich:datascroller id="ds2"></rich:datascroller>
				            </f:facet>
				        </rich:extendedDataTable> 
				        </h:panelGrid>
	                            <br>
	                            
	                        
	                          <h:outputText value="#{mes.end_cust_no} "/>&nbsp;
	                   		  <h:inputText disabled="true"  value = "#{newPosManagedBean.customer.accountancyId}"/>&nbsp; 
	                   		  <h:outputText value="#{mes.end_user_name} "/>&nbsp;
	                   		  <h:inputText  disabled="true" value = "#{newPosManagedBean.customer.name}"/>&nbsp;
	                   		  
	                   		  <h:inputHidden   value="#{newPosManagedBean.customer.id}" />
	                   		  <h:outputText  value="#{mes.user_city} "/>&nbsp;
	                   		  <h:inputText  disabled="true"   value = "#{newPosManagedBean.customer.location}"/>&nbsp;
	                   		  <h:outputText value="#{mes.state} "/>&nbsp;
	                   		  <h:inputText disabled="true"   value = "#{newPosManagedBean.customer.state}"/>&nbsp;
	                   		  <br><br>
	                   		  <h:outputText value="#{mes.zip_code} "/>&nbsp;&nbsp;&nbsp;
	                   		  <h:inputText disabled="true"  value = "#{newPosManagedBean.customer.zipCode}"/>&nbsp;
	                   		  <h:outputText value="#{mes.country} "/>&nbsp;
	                   		  <h:inputText disabled="true" value = "#{newPosManagedBean.customer.country}"/>&nbsp;
	                   		 
	                    		<br>
	                    		<br>
	                    		<h:outputText value="#{mes.disti_invoice} "/>&nbsp;
	                   		  <h:inputText value = "#{newPosManagedBean.distiInvoice}"/>&nbsp;
	                    	  	<h:outputText value="#{mes.disti_line} "/>&nbsp;
	                   		  <h:inputText value = "#{newPosManagedBean.distiLine}"/>&nbsp;
	                   		  <br>  
	                   		  <br>
	                   		  <h:outputText value="#{mes.dpa_number} "/>&nbsp;
	                   		  <h:inputText disabled="true" value = "#{newPosManagedBean.dpaId}"/>&nbsp;
	                   		  <h:outputText value="#{mes.sdc_extended} "/>&nbsp;
	                   		  <h:inputText value = "#{newPosManagedBean.sdc}"/>&nbsp;
	                   		   <h:outputText value="#{mes.dpa_cost} "/>&nbsp;
	                   		  <h:inputText value = "#{newPosManagedBean.dpaCost}"/>&nbsp;
	                   		  <br>  
	                   		  <br>
	                   		  <h:outputText value="#{mes.item_num} "/>&nbsp;
	                   		  <h:inputText disabled="true" value = "#{newPosManagedBean.product.dialogicItemKey}"/>&nbsp;
	                   		  <h:outputText value="#{mes.item_description} "/>&nbsp;
	                   		  <h:inputText disabled="true" value = "#{newPosManagedBean.product.productName}"/>&nbsp;
	                   		    <br>  
	                   		  <br>
	                   		  <h:outputText value="#{mes.qty} "/>
	                   		  <rich:inputNumberSpinner  value = "#{newPosManagedBean.qty}"  maxValue="#{newPosManagedBean.maxQty}" />
	                   		  
	                   		  <br>  
	                   		  <br>
	                   		  <h:outputText value="#{mes.trans_curr} "/>&nbsp;
	                    	  <h:inputText value = "#{newPosManagedBean.transCurr}"/>&nbsp;
	                   		  <h:outputText value="#{mes.distributor_resale_price} "/>&nbsp;
	                    	  <h:inputText value = "#{newPosManagedBean.distributorResalePrice}"/>&nbsp;
	                    	  <h:outputText value="#{mes.ship_date} "/>&nbsp;
	                    	  <rich:calendar value = "#{newPosManagedBean.shipDate}"/>&nbsp;
	                    	  <br>
	                    	  <br>
	                    	  <a4j:commandButton  value="add to POS" action="#{newPosManagedBean.putProdIntoPosWithDpa}" reRender="posPrdsTable, products, fields" />
	                    	  </rich:tab>
	                    	  <rich:tab label="#{mes.pos_tab_ndpa}">
									<font size="4" color="red">*</font>
 
		                   		  <h:outputText value="#{mes.end_user_name} "/>&nbsp; 
	                   			  <h:inputText id="customerI" value="#{newPosManagedBean.customerN.name}" />
	                        		 <rich:suggestionbox for="customerI" var="customer" suggestionAction="#{newPosManagedBean.autoCompleteCustomer}" 
	           						  usingSuggestObjects="true"
	           						 onobjectchange="fillCst(#{rich:element('customerID')},#{rich:element('customerA')},#{rich:element('customerL')}, #{rich:element('customerS')},#{rich:element('customerZ')},#{rich:element('customerC')},#{rich:component('suggestionC')});"
	           						 id="suggestionC">
	                         
	                       		      <h:column>
	                       		     <h:outputText value="#{customer.name}" />
	                       		     </h:column>
	                            
	                      			   </rich:suggestionbox>

								  <h:outputText value="#{mes.end_cust_no} "/>&nbsp;
		                   		  <h:inputText id="customerA" value = "#{newPosManagedBean.customerN.accountancyId}"/>&nbsp; 		                   		  
		                   		  <h:inputHidden  id = "customerID" value="#{newPosManagedBean.customerN.id}" />
		                   		  <h:outputText  value="#{mes.user_city} "/>&nbsp;
		                   		  <h:inputText    id="customerL"  value = "#{newPosManagedBean.customerN.location}"/>&nbsp;
		                   		  <h:outputText value="#{mes.state} "/>&nbsp;
		                   		  <h:inputText id="customerS"  value = "#{newPosManagedBean.customerN.state}"/>&nbsp;
		                   		  <br>
		                   		  <br>
		                   		  <h:outputText value="#{mes.zip_code} "/>&nbsp;
		                   		  <h:inputText  id="customerZ" value = "#{newPosManagedBean.customerN.zipCode}"/>&nbsp;
		                   		  <h:outputText value="#{mes.country} "/>&nbsp;
		                   		  <h:inputText  id="customerC" value = "#{newPosManagedBean.customerN.country}"/>&nbsp;
		                   		 
		                    		<br>
		                    		<br>
		                    		<h:outputText value="#{mes.disti_invoice} "/>&nbsp;
		                   		  <h:inputText value = "#{newPosManagedBean.distiInvoiceN}"/>&nbsp;
		                    	  	<h:outputText value="#{mes.disti_line} "/>&nbsp;
		                   		  <h:inputText value = "#{newPosManagedBean.distiLineN}"/>&nbsp;
		                   		  <br>  
		                   		  <br>
		                   		  <h:outputText value="#{mes.sdc_extended} "/>&nbsp;
		                   		  <h:inputText value = "#{newPosManagedBean.sdcN}"/>&nbsp;
		                   		  <br>  
		                   		  <br>
		                   		  
		                   		  
		                   		  <font size="4" color="red">*</font>
		                   		  <h:outputText value="#{mes.item_num} "/>&nbsp;
		                   		  <h:inputText id="itemI" value="#{newPosManagedBean.productN.dialogicItemKey}" />
	                        		 <rich:suggestionbox for="itemI" var="prd" suggestionAction="#{newPosManagedBean.autoCompletePrd}"  
	           						  usingSuggestObjects="true"
	           						 onobjectchange="fillPrd(#{rich:element('itemID')},#{rich:element('itemD')},#{rich:component('suggestionP')});"
	           						 id="suggestionP">
	                         
	                       		      <h:column>
	                       		     <h:outputText value="#{prd.dialogicItemKey}" />
	                       		     </h:column>
	                            
	                      			   </rich:suggestionbox>
		                   		  
		                   		  <h:outputText value="#{mes.item_description} "/>&nbsp;
		                   		  <h:inputText id="itemD" value = "#{newPosManagedBean.productN.productName}"/>&nbsp;
		                   		  <h:inputHidden  id="itemID" value="#{newPosManagedBean.productN.id}" />
		                   		  
		                   		    <br>  
		                   		  <br>
		                   		  <h:outputText value="#{mes.qty} "/>
		                   		  <rich:inputNumberSpinner  value = "#{newPosManagedBean.qtyN}" maxValue="9999" />
		                   		  
		                   		  <br>  
		                   		  <br>
		                   		  <h:outputText value="#{mes.trans_curr} "/>&nbsp;
		                    	  <h:inputText value = "#{newPosManagedBean.transCurrN}"/>&nbsp;
		                   		  <h:outputText value="#{mes.distributor_resale_price} "/>&nbsp;
		                    	  <h:inputText value = "#{newPosManagedBean.distributorResalePriceN}"/>&nbsp;
		                    	  <h:outputText value="#{mes.ship_date} "/>&nbsp;
		                    	  <rich:calendar value = "#{newPosManagedBean.shipDateN}"/>&nbsp;
		                    	  <br>
		                    	  <br>
		                    	  <a4j:commandButton  value="add to POS" action="#{newPosManagedBean.putProdIntoPosWithoutDpa}" reRender="posPrdsTable, products, fields" />
		                    </rich:tab>
	                        </rich:tabPanel>
	                         <rich:panel id= "posPrdsPanel">
	 							<rich:extendedDataTable id ="posPrdsTable" value="#{newPosManagedBean.posProductList}" var="prod" width="450px" columnClasses="center"
				       				rowKeyVar="row"	 rows="15" height="350px" >
	 							  <rich:column>
	 			          		  <f:facet name="header">
				                   		 <h:outputText value="#"/>
				                	</f:facet>
				               		 <h:outputText value="#{row}"/> 
				          		  </rich:column>	
								   <rich:column >
				               		 <f:facet name="header">
				                   		 <h:outputText value="#{mes.end_user_name} "/>
				                	</f:facet>
				               		 <h:outputText value="#{prod.customer.name}"/> 
				          		  </rich:column>			          		  
	
								<rich:column >
				               		 <f:facet name="header">
				                   		 <h:outputText value="#{mes.item_num} "/>
				                	</f:facet>
				               		 <h:outputText value="#{prod.product.dialogicItemKey}"/> 
				          		  </rich:column>
								<rich:column >
				               		 <f:facet name="header">
				                   		 <h:outputText value="#{mes.item_description} "/>
				                	</f:facet>
				               		 <h:outputText value="#{prod.product.productName}"/> 
				          		  </rich:column>
									<rich:column>
									 	<a4j:commandLink value="#{mes.remove }" action="#{newPosManagedBean.removePrd}"  reRender="posPrdsPanel, fields">
				                			<a4j:actionparam name="pr"  value="#{row}" assignTo="#{newPosManagedBean.removePrdIdx}"/>
					            		</a4j:commandLink>
									</rich:column>	          		  
	                        	</rich:extendedDataTable>
	                        	<h:commandButton value="#{mes.pos_create }" action="#{newPosManagedBean.createRequest }" onclick="return confirm('#{mes.prompt }')"  />
	                        	 <h:commandButton action="#{newPosManagedBean.createDraft}" value="#{mes.pos_save_draft }" onclick="return confirm('#{mes.prompt }')"  />&nbsp;&nbsp;
	                        </rich:panel>

				</a4j:form>
            </f:view>
      </body>
      </html>

